<template>
  <div class="Navtop" @mouseleave="leave">
    <div class="nav_top">
      <div class="left_box">
        <ul>
          <li>
            <router-link to="">品牌</router-link>
          </li>
          <li>
            <router-link to="">OriginOS</router-link>
          </li>
          <li>
            <router-link to="">体验店</router-link>
          </li>
          <li>
            <router-link to="">社区</router-link>
          </li>
        </ul>
      </div>
      <div class="right_box">
        <ul>
          <li>
            <router-link to="">
              <i class="el-icon-download">下载APP</i>
            </router-link>
          </li>
          <li @click="skipCar">
            <router-link to=""
              >购物车
              <i class="el-icon-shopping-cart-2"></i>
            </router-link>
          </li>
          <li @mouseover="over">
            <router-link to="">
              <i class="el-icon-s-custom">个人中心</i>
            </router-link>
          </li>
        </ul>

        <div
          class="userbox"
          v-show="userFlag"
          @mouseleave="leave"
          v-if="!this.$store.state.flag"
        >
          <div class="jiantou"></div>
          <p>
            <i class="el-icon-sort">
              <router-link to="/login">登录</router-link>
            </i>
          </p>
          <p>
            <i class="el-icon-s-check">
              <router-link to="/register">注册</router-link>
            </i>
          </p>
        </div>

        <!-- 登录之后 -->
        <div
          class="userbox"
          v-show="userFlag"
          @mouseleave="leave"
          v-if="this.$store.state.flag"
        >
          <div class="jiantou"></div>
          <p>
            <i class="el-icon-sort">
              <router-link to="/shopcar">我的订单</router-link>
            </i>
          </p>
          <p>
            <i class="el-icon-s-check">
              <router-link to="/">账户中心</router-link>
            </i>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Navtop",
  data() {
    return {
      userFlag: false,
      time: 3,
    };
  },
  methods: {
    over() {
      this.userFlag = true;
    },
    leave() {
      this.userFlag = false;
    },
    skipCar() {
      if (sessionStorage.getItem("user")) {
        this.$router.push({ path: "/shopcar" });
      } else {
        alert("请先登陆账户！！！")
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.nav_top {
  padding: 0 5%;
  background-color: #242933;
  height: 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .left_box {
    ul {
      display: flex;
      li {
        margin-right: 50px;
        font-size: 12px;

        a {
          color: #838892;
          text-decoration: none;
        }
      }
    }
  }
  .right_box {
    ul {
      display: flex;
      li {
        margin-left: 50px;
        font-size: 12px;
        a {
          color: #838892;
          text-decoration: none;
        }
      }
    }
  }
}

.right_box {
  position: relative;
  .userbox {
    position: absolute;
    z-index: 1000;
    top: 40px;
    right: -70px;
    width: 200px;
    height: 80px;
    border-radius: 20px;
    background-color: #e9eefa;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    .jiantou {
      position: absolute;
      border: 10px solid;
      border-color: transparent transparent #e9eefa transparent;
      z-index: 1000;
      top: -20px;
      right: 50%;
      transform: translateX(50%);
    }
    p {
      text-align: center;
      font-size: 16px;
      width: 200px;
      a {
        margin: 0 10px;
        transition: all 0.5s;
        color: #000;
      }
      :hover {
        color: aqua;
        transition: all 0.5s;
      }
    }
  }
}
</style>